package org.abc.fund.controller.strategy.response;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Data;
import org.abc.fund.entity.strategy.CombinationStrategy;

@Data
@Builder
public class CombinationStrategyResponse {
  private Long id;
  private String name;
  private CombinationStrategy.Type type;
  private CombinationStrategy.Status status;
  private String description;
  private String targetAudience;
  private String riskLevel;
  private String benchmark;
  private String rejectionReason;
  private RebalanceRuleResponse rebalanceRule;
  private List<StrategyComponentResponse> components;
  private LocalDate createdAt;
  private LocalDate updatedAt;

  public static CombinationStrategyResponse fromEntity(CombinationStrategy strategy) {
    if (strategy == null) return null;
    return CombinationStrategyResponse.builder()
        .id(strategy.getId())
        .name(strategy.getName())
        .type(strategy.getType())
        .status(strategy.getStatus())
        .description(strategy.getDescription())
        .rejectionReason(strategy.getRejectionReason())
        .targetAudience(strategy.getTargetAudience())
        .riskLevel(strategy.getRiskLevel())
        .benchmark(strategy.getBenchmark())
        .createdAt(strategy.getCreatedAt())
        .updatedAt(strategy.getUpdatedAt())
        .rebalanceRule(RebalanceRuleResponse.fromEntity(strategy.getRebalanceRule()))
        .components(
            strategy.getComponents() == null
                ? Collections.emptyList()
                : strategy.getComponents().stream()
                    .map(StrategyComponentResponse::fromEntity) // 方法引用
                    .collect(Collectors.toList()))
        .build();
  }
}
